<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui, viewport-fit=cover">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>My App</title>
    <link rel="stylesheet" href="../../packages/core/css/framework7.min.css">
    <link rel="stylesheet" href="../../css/framework7-icons.css">
  </head>
  <body>
    <div id="app"></div>
    <template id="app-template">
      <f7-app>
        <f7-view main>
          <f7-page>
            <f7-navbar title="Virtual List">
              <f7-subnavbar :inner="false">
                <f7-searchbar
                  search-container=".virtual-list"
                  search-item="li"
                  search-in=".item-title"
                ></f7-searchbar>
              </f7-subnavbar>
            </f7-navbar>
            <f7-block>
              <p>Virtual List allows to render lists with huge amount of elements without loss of performance. And it is fully compatible with all Framework7 list components such as Search Bar, Infinite Scroll, Pull To Refresh, Swipeouts (swipe-to-delete) and Sortable.</p>
              <p>Here is the example of virtual list with 10 000 items:</p>
            </f7-block>
            <f7-list class="searchbar-not-found">
              <f7-list-item title="Nothing found"></f7-list-item>
            </f7-list>
            <f7-list
              class="searchbar-found"
              medial-list
              virtual-list
              :virtual-list-params="{ items, searchAll, renderExternal, height: $theme.ios ? 63 : 73}"
            >
              <ul>
                <f7-list-item
                  v-for="(item, index) in vlData.items"
                  :key="index"
                  media-item
                  link="#"
                  :title="item.title"
                  :subtitle="item.subtitle"
                  :style="`top: ${vlData.topPosition}px`"
                ></f7-list-item>
              </ul>
            </f7-list>
          </f7-page>
        </f7-view>
      </f7-app>
      
    </template>
    <script>
      var component = {
        data() {
          const items = [];
          for (let i = 1; i <= 10000; i += 1) {
            items.push({
              title: `Item ${i}`,
              subtitle: `Subtitle ${i}`,
            });
          }
          return {
            items,
            vlData: {
              items: [],
            },
          };
        },
        methods: {
          searchAll(query, items) {
            const found = [];
            for (let i = 0; i < items.length; i += 1) {
              if (items[i].title.toLowerCase().indexOf(query.toLowerCase()) >= 0 || query.trim() === '') found.push(i);
            }
            return found; // return array with mathced indexes
          },
          renderExternal(vl, vlData) {
            this.vlData = vlData;
          },
        },
      }
    </script>
    <script src="../../packages/vue/vue.min.js"></script>
    <script src="../../packages/vue/framework7-vue.min.js"></script>
    <script src="../../packages/core/js/framework7.min.js"></script>
    <script>
      var theme = 'ios';
      if (location.href.indexOf('theme=md') >= 0) theme = 'md';
      
      if (Framework7.use) Framework7.use(Framework7Vue, { theme: theme });
      else if (Framework7.Class && Framework7.Class.use) Framework7.Class.use(Framework7Vue, { theme: theme });
      
      var plugin = {
        params: {
          theme: theme,
        }
      };
      
      if (Framework7.use) Framework7.use(plugin);
      else if (Framework7.Class && Framework7.Class.use) Framework7.Class.use(plugin);
      
      if (typeof component === 'undefined') {
        var component = {};
      }
      if (typeof routes === 'undefined') {
        var routes = [];
      }
      component.el = '#app';
      component.template = '#app-template';
      
      new Vue(component);
    </script>
  </body>
</html>